home *** CD-ROM | disk | FTP | other *** search
/ ADA Programming Guide / ADA Programming Guide.iso / ada_gnu / adainc / s-taskin.ads < prev    next >
Text File  |  1996-01-30  |  9KB  |  277 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                 GNU ADA RUNTIME LIBRARY (GNARL) COMPONENTS               --
  4. --                                                                          --
  5. --                        S Y S T E M . T A S K I N G                       --
  6. --                                                                          --
  7. --                                  S p e c                                 --
  8. --                                                                          --
  9. --                             $Revision: 1.13 $                             --
  10. --                                                                          --
  11. --       Copyright (c) 1991,1992,1993,1994, FSU, All Rights Reserved        --
  12. --                                                                          --
  13. -- GNARL is free software; you can redistribute it  and/or modify it  under --
  14. -- terms  of  the  GNU  Library General Public License  as published by the --
  15. -- Free Software  Foundation;  either version 2, or (at  your  option)  any --
  16. -- later  version.  GNARL is distributed  in the hope that  it will be use- --
  17. -- ful, but but WITHOUT ANY WARRANTY;  without even the implied warranty of --
  18. -- MERCHANTABILITY  or  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Gen- --
  19. -- eral Library Public License  for more details.  You should have received --
  20. -- a  copy of the GNU Library General Public License along with GNARL;  see --
  21. -- file COPYING.LIB.  If not,  write to the  Free Software Foundation,  675 --
  22. -- Mass Ave, Cambridge, MA 02139, USA.                                      --
  23. --                                                                          --
  24. ------------------------------------------------------------------------------
  25.  
  26. --  This package provides necessary type definitions for compiler interface.
  27.  
  28. with System.Task_Primitives;
  29. --  Used for,  Task_Primitives.Lock
  30.  
  31. with System.Compiler_Exceptions;
  32. --  Used for, Exception_ID
  33.  
  34. package System.Tasking is
  35.  
  36.    --  Task_ID related definitions
  37.  
  38.    type Task_ID is private;
  39.  
  40.    Null_Task : constant Task_ID;
  41.  
  42.    function Self return Task_ID;
  43.    pragma Inline (Self);
  44.  
  45.    --  Task size, initial_state and interrupt info.
  46.  
  47.    type Task_Procedure_Access is access procedure (Arg : System.Address);
  48.  
  49.    type Task_Storage_Size is new integer;
  50.  
  51.    type Interrupt_ID is range 0 .. 31;
  52.  
  53.    --  Some Constants
  54.  
  55.    Null_Entry : constant := 0;
  56.  
  57.    Max_Entry : constant := System.Max_Int;
  58.  
  59.    Interrupt_Entry : constant := -2;
  60.  
  61.    Cancelled_Entry : constant := -1;
  62.  
  63.    type Entry_Index is range Interrupt_Entry .. Max_Entry;
  64.  
  65.    --  PO related definitions
  66.  
  67.    Null_Protected_Entry : constant := Null_Entry;
  68.  
  69.    Max_Protected_Entry : constant := Max_Entry;
  70.  
  71.    type Protected_Entry_Index is new Entry_Index
  72.      range Null_Protected_Entry .. Max_Protected_Entry;
  73.  
  74.    subtype Positive_Protected_Entry_Index is
  75.      Protected_Entry_Index range  1 .. Protected_Entry_Index'Last;
  76.  
  77.    type Call_Modes is (Simple_Call, Conditional_Call, Asynchronous_Call);
  78.  
  79.    --  definition for Protecton has to be private. But, currently
  80.    --  generates gnat internal error.
  81.  
  82.    type Protection (Num_Entries : Protected_Entry_Index) is private;
  83.  
  84.    type Protection_Access is access Protection;
  85.  
  86.    type Communication_Block is private;
  87.  
  88.    type Barrier_Vector is array (Protected_Entry_Index range <>) of Boolean;
  89.  
  90.    --  Rendezvous related definitions
  91.  
  92.    Null_Task_Entry : constant := Null_Entry;
  93.  
  94.    Max_Task_Entry : constant := Max_Entry;
  95.  
  96.    type Task_Entry_Index is new Entry_Index
  97.      range Null_Task_Entry .. Max_Task_Entry;
  98.  
  99.    No_Rendezvous : constant := 0;
  100.  
  101.    Max_Select : constant Integer := Integer'Last;
  102.    --  RTS-defined
  103.  
  104.    subtype Select_Index is Integer range No_Rendezvous .. Max_Select;
  105. --   type Select_Index is range No_Rendezvous .. Max_Select;
  106.  
  107.    subtype Positive_Select_Index is
  108.      Select_Index range 1 .. Select_Index'Last;
  109.  
  110.    type Accept_Alternative is record --  should be packed
  111.       Null_Body : Boolean;
  112.       S : Task_Entry_Index;
  113.    end record;
  114.  
  115.    type Accept_List is
  116.      array (Positive_Select_Index range <>) of Accept_Alternative;
  117.  
  118.    type Accept_List_Access is access constant Accept_List;
  119.  
  120.    type Select_Modes is (
  121.      Simple_Mode,
  122.      Else_Mode,
  123.      Terminate_Mode);
  124.  
  125.    --  Abortion related declarations
  126.  
  127.    Max_ATC_Nesting : constant Natural := 20;
  128.  
  129.    type Task_List is array (Positive range <>) of Task_ID;
  130.  
  131.    --  Task_Stage related types
  132.  
  133.    type Master_ID is private;
  134.  
  135.    type Access_Boolean is access Boolean;
  136.  
  137.    type Size_Type is new Task_Storage_Size;
  138.  
  139.    Unspecified_Size : constant Size_Type := Size_Type'First;
  140.  
  141.    type Activation_Chain is limited private;
  142.  
  143.    type Activation_Chain_Access is access all Activation_Chain;
  144.  
  145.    Unspecified_Priority : constant Integer := System.Priority'First - 1;
  146.  
  147.    -------------------------------------
  148.  
  149.    --  This part should go to s-taruty.ads when we can move queuing related
  150.    --  stuffs to s-tasque.ad?
  151.  
  152.    subtype ATC_Level_Base is Integer range 0 .. Max_ATC_Nesting;
  153.  
  154.    ATC_Level_Infinity : constant ATC_Level_Base := ATC_Level_Base'Last;
  155.  
  156.    subtype ATC_Level is ATC_Level_Base range
  157.      ATC_Level_Base'First .. ATC_Level_Base'Last - 1;
  158.  
  159.    subtype ATC_Level_Index is ATC_Level
  160.      range ATC_Level'First + 1 .. ATC_Level'Last;
  161.  
  162.    -----------------------------------------
  163.  
  164.    --  This part should go to private part right before the type Protection.
  165.  
  166.    Priority_Not_Boosted : constant Integer := System.Priority'First - 1;
  167.  
  168.    subtype Rendezvous_Priority is Integer
  169.      range Priority_Not_Boosted .. System.Priority'Last;
  170.  
  171.    type Entry_Call_Record;
  172.  
  173.    type Entry_Call_Link is access Entry_Call_Record;
  174.  
  175.    type Entry_Queue is record
  176.       Head : Entry_Call_Link;
  177.       Tail : Entry_Call_Link;
  178.    end record;
  179.  
  180.    type Entry_Call_Record is record
  181.  
  182.       Prev : Entry_Call_Link;
  183.       Next : Entry_Call_Link;
  184.  
  185.       Call_Claimed : Boolean;
  186.       --  This flag is True if the call has been queued
  187.       --  and subsequently claimed
  188.       --  for service or cancellation.
  189.       --  Protection : Test_And_Set/gloabal update or some similar mechanism
  190.       --  (e.g. global mutex).
  191.       --  Caution : on machines were we use Test_And_Set, we may not want this
  192.       --  field packed.  For example, the SPARC atomic ldsub instruction
  193.       --  effects a whole byte.
  194.  
  195.       Self  : Task_ID;
  196.       Level : ATC_Level;
  197.       --  One of Self and Level are redundent in this implementation, since
  198.       --  each Entry_Call_Record is at Self.Entry_Calls (Level).  Since we must
  199.       --  have access to the entry call record to be reading this, we could
  200.       --  get Self from Level, or Level from Self.  However, this requires
  201.       --  non-portable address arithmetic.
  202.  
  203.       Mode : Call_Modes;
  204.       Abortable : Boolean;
  205.  
  206.       Done : Boolean;
  207.       --  Protection : Self.L.
  208.  
  209.       E : Entry_Index;
  210.  
  211.       Prio : System.Any_Priority;
  212.  
  213.       --  The above fields are those that there may be some hope of packing.
  214.       --  They are gathered together to allow for compilers that lay records
  215.       --  out contigously, to allow for such packing.
  216.  
  217.       Uninterpreted_Data : System.Address;
  218.  
  219.       Exception_To_Raise : Compiler_Exceptions.Exception_ID;
  220.       --  The exception to raise once this call has been completed without
  221.       --  being aborted.
  222.  
  223.       --  Server : Server_Record;
  224.  
  225.       Called_Task : Task_ID;
  226.       --  For task entry calls only.
  227.  
  228.       Acceptor_Prev_Call : Entry_Call_Link;
  229.       --  For task entry calls only.
  230.  
  231.       Acceptor_Prev_Priority : Rendezvous_Priority;
  232.       --  For task entry calls only.
  233.       --  The priority of the most recent prior call being serviced.
  234.       --  For protected entry calls, this function should be performed by
  235.       --  GNULLI ceiling locking.
  236.  
  237.       --  Called_PO : Protection_Access;
  238.       --  Compiler bug when compiler queue package as child.
  239.       --  Work-around: declare access type as System.Address cast types.
  240.       Called_PO : System.Address;
  241.       --  For protected entry calls only.
  242.  
  243.    end record;
  244.  
  245.    type Protected_Entry_Queue_Array is
  246.         array (Protected_Entry_Index range <>) of
  247.         Entry_Queue;
  248.  
  249. ----------------------------------
  250. private
  251.  
  252.    type Dummy is new Integer;
  253.  
  254.    type Task_ID is access Dummy;
  255.  
  256.    Null_Task : constant Task_ID := null;
  257.  
  258.    type Activation_Chain is new Task_ID;
  259.  
  260.    type Master_ID is new Integer;
  261.  
  262.    type Communication_Block is record
  263.       Self : Task_ID;
  264.    end record;
  265.  
  266.    type Protection (Num_Entries : Protected_Entry_Index) is record
  267.         L : Task_Primitives.Lock;
  268.         Pending_Call : Entry_Call_Link;
  269.         Call_In_Progress : Entry_Call_Link;
  270.         Ceiling : System.Priority;
  271.         Old_Base_Priority : System.Priority;
  272.         Pending_Action : Boolean;
  273.         Entry_Queues : Protected_Entry_Queue_Array (1 .. Num_Entries);
  274.    end record;
  275.  
  276. end System.Tasking;
  277.